package jp.co.tms.internal.data;

import java.nio.channels.SocketChannel;

public class RunServer implements IRunServer {
	
	private SocketChannel _sc;
	
	private int _id;
	
	private int _cpus;
	
	private int _tasks;
	
	private boolean _enable;
	
	public RunServer(SocketChannel sc, int id, int cpus){
		this._sc = sc;
		this._id = id;
		this._cpus = cpus;
		this._tasks = 0;
		this._enable = true;
	}

	@Override
	public SocketChannel getSocketChannel(){
		return _sc;
	}
	
	@Override
	public void setSocketChannel(SocketChannel sc) {
		this._sc = sc;
	}

	@Override
	public int getServerId() {
		return _id;
	}

	@Override
	public void setServerId(int id) {
		this._id = id;
	}

	@Override
	public int getCpus() {
		return _cpus;
	}

	@Override
	public void setCpus(int cpus) {
		this._cpus = cpus;
	}
	
	public void addTaskCount(){
		_tasks++;
	}
	
	public void remTaskCount(){
		_tasks--;
	}
	
	public int getTaskCount(){
		return _tasks;
	}
	
	public boolean isEnable() {
		return _enable;
	}

	public void setEnable(boolean enable) {
		this._enable = enable;
	}

	@Override
	public boolean hasIdleCpu() {
		if (getCpus() > getTaskCount())
			return true;
		return false;
	}
}
